﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace zzOSSSynch
{
    public class YFLog
    {
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger("WebLogger");
        public static void logInfo(string logstr)
        {
            Console.WriteLine(logstr);
            initLog4net();
            logger.Info(logstr);
        }

        public static void logInfo(string format, params object[] args)
        {
            Console.WriteLine(format, args);
            initLog4net();
            logger.InfoFormat(format, args);
        }

        public static void logError(string logstr)
        {
            Console.WriteLine(logstr);
            initLog4net();
            logger.Error(logstr);
        }

        public static void logError(string format, params object[] args)
        {
            Console.WriteLine(format, args);
            initLog4net();
            logger.ErrorFormat(format, args);
        }


        private static void initLog4net()
        {
            if (!logger.IsInfoEnabled)
            {
                var logCfg = new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");
                log4net.Config.XmlConfigurator.ConfigureAndWatch(logCfg);
            }
        }
    }
}
